package com.mifengs.mall;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import java.net.HttpURLConnection;
import java.net.URL;

import static org.junit.Assert.*;

/**
 * Instrumentation test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {

    private final String TAG = "Test";

    @Test
    public void useAppContext() throws Exception {
        // Context of the app under test.
        final Context appContext = InstrumentationRegistry.getTargetContext();


//        NetWork.getHomeDataApi().getHomeData()
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Observer<ResponseBean<HomeResponseBean>>() {
//                    @Override
//                    public void onCompleted() {
//
//                    }
//
//                    @Override
//                    public void onError(Throwable throwable) {
//                        LogUtil.i("test","test:"+throwable.toString());
//                        assertEquals("com.mifengs.mall", appContext.getPackageName());
////                        mView.showLongToast(throwable.getMessage());
//                    }
//
//                    @Override
//                    public void onNext(ResponseBean<HomeResponseBean> responseBean) {
//                        LogUtil.i("test","test:"+responseBean.toString());
//                        if (responseBean.getStatus().equals(Constant.SUCCESS_CODE)){
//                            HomeInfo homeInfo = responseBean.getParamer().getAppPageDecorateDto();
//                            ArrayList<TabBean> tabBeanList = (ArrayList<TabBean>) homeInfo.getAppTabDecorateDtoList();
//                        }
//                        assertEquals("com.mifengs.mall", appContext.getPackageName());
//                    }
//                });

        try {
            //连接地址
            URL u = new URL("https://www.mifengs.com/legendshop_api/mIndex.do");
            LogUtil.i(TAG, u.toString());
            HttpURLConnection c = (HttpURLConnection) u.openConnection();
            c.setRequestMethod("GET");

            c.connect();

            int code=c.getResponseCode();
            int lenghtOfFile = c.getContentLength();


        } catch (Exception e) {
            LogUtil.e(TAG,e.getMessage());
        }

        assertEquals("com.mifengs.mall", appContext.getPackageName());

    }




}
